﻿using FtpFileBackup_Oracle.LogHelper;
using FtpFileBackup_Oracle.DbHelper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FtpFileBackup_Oracle.DataBaseBackup.SqlServer
{
    public class OracleBackup : IDataBaseBackup
    {
        public OracleBackup()
        {
        }

        public void Excute()
        {
            string baseBackupPath = ConfigurationManager.AppSettings["serverSaveBasePath"];

            var filePath = $"{baseBackupPath}{DateTime.Now.ToString("yyyyMMddHH0000")}.dmp";

            log4netHelper.Info($"开始数据库的备份文件压缩");

            FileCompress(new string[] { filePath });

            //DeleteSourceFile(new string[] { filePath });

            log4netHelper.Info($"完成数据库的备份文件压缩");
        }

        private void FileCompress(string[] paths)
        {
            foreach (string path in paths)
            {
                SevenZipTool.Compress(path, path.Replace(".dmp", ".7z"));
            }
        }

        private void DeleteSourceFile(string[] paths)
        {
            foreach (string path in paths)
            {
                File.Delete(path);
            }
        }
    }
}
